/**
  * @file     	openmv.c
  * @author   	YangHaifeng
  * @email   	2995339193@qq.com
  * @version	V0.0
  * @license  	GNU General Public License (GPL)  
  * @detail		please follow the license!!!
  * @attention
  *  this file is aim to do something with openmv									
  *   																	
  * @htmlonly 
  * <span style="font-weight: bold">History</span> 
  * @endhtmlonly 
  * Version|Auther|Describe
  * ------|----|-------- 
  * V0.0|YangHaifeng|Create File
  * <h2><center>&copy;COPYRIGHT YangHaifeng All Rights Reserved.</center></h2>
  */ 
  
  
#include "openmv.h"


/**
 * @brief openmv初始化
 * @param None
 * @retval None
 * @note 波特率-9600
 * @author YangHaifeng
 */
void openmv_init(void)
{
	eUSCI_UART_Config uartConfig;
	
	
	//配置GPIO复用
	GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P3,GPIO_PIN2|GPIO_PIN3,GPIO_PRIMARY_MODULE_FUNCTION);
	
	
	//配置结构体
	uartConfig.selectClockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK;
	uartConfig.clockPrescalar = 312;
	uartConfig.firstModReg = 8;
	uartConfig.secondModReg = 0;
	uartConfig.overSampling = 1;
	uartConfig.parity = EUSCI_A_UART_NO_PARITY;
	uartConfig.msborLsbFirst = EUSCI_A_UART_LSB_FIRST;
	uartConfig.numberofStopBits = EUSCI_A_UART_ONE_STOP_BIT;
	uartConfig.uartMode = EUSCI_A_UART_MODE;
	
	//优先级最高
	Interrupt_setPriority(INT_EUSCIA2,0<<5);
	
	//初始化串口
	UART_initModule(EUSCI_A2_BASE, &uartConfig);
	
	
	//开启串口
	UART_enableModule(EUSCI_A2_BASE);
	
	
	//开启串口相关中断
	UART_enableInterrupt(EUSCI_A2_BASE, EUSCI_A_UART_RECEIVE_INTERRUPT);
	
	
	//开启串口端口中断
	Interrupt_enableInterrupt(INT_EUSCIA2);
	

	//开启总中断
	Interrupt_enableMaster();
}



/**
 * @brief 实例化
 * @author YangHaifeng
 */
see_t openmv = {0};



/**
 * @brief 串口中断服务函数
 * @param None
 * @retval None
 * @author YangHaifeng
 */
void EUSCIA2_IRQHandler(void)
{
    uint32_t status;

    UART_clearInterruptFlag(EUSCI_A2_BASE, status);
	
	status = UART_getEnabledInterruptStatus(EUSCI_A2_BASE);

    if(status & EUSCI_A_UART_RECEIVE_INTERRUPT_FLAG)
    {
		openmv.rho = UART_receiveData(EUSCI_A2_BASE);
    }
}





